import { LinRouter } from 'lin-mizar';
import { MalfunctionDao } from '../../dao/malfunction';
import { CreateMalfunctionTypeValidator } from '../../validator/malfunction';
const malfunctionDto = new MalfunctionDao();

const malfunctionApi = new LinRouter({
  prefix: '/mini/malfunction'
});

malfunctionApi.get('/type/list', async ctx => {
  const list = await malfunctionDto.getMalfunctionType();
  ctx.successData(list);
});

malfunctionApi.post('/type', async ctx => {
  const v = await new CreateMalfunctionTypeValidator().validate(ctx);
  const reslut = await malfunctionDto.createMalfunctionType(v);
  if (reslut) {
    ctx.success({
      code: 1
    });
  }
});

module.exports = { malfunctionApi };
